%利用神经网络进行分类
clear all
x=[1.24 1.36 1.38 1.38 1.38 1.40 1.48 1.54 1.56 1.14 1.18 1.20 1.26 1.28 1.30;...
    1.72 1.74 1.64 1.82 1.90 1.70 1.82 1.82 2.08 1.78 1.96 1.86 2.0 2.0 1.96];
y=[1 1 1 1 1 1 1 1 1 0 0 0 0 0 0;...
   0 0 0 0 0 0 0 0 0 1 1 1 1 1 1];

xmin1=min(x(1,:));
xmax1=max(x(1,:));
xmin2=min(x(2,:));
xmax2=max(x(2,:));
%设定迭代次数
net.trainparam.epochs=10000;
%网络初始化
net=newff([xmin1,xmax1;xmin2,xmax2],[8,8,8,8,2],{'tansig','logsig','logsig','tansig','tansig'});
%训练网络
[net,tr,y1,e]=train(net,x,y);

X=[1.24 1.28 1.40;...
    1.80 1.84 2.04];
y2=sim(net,X)
%网络泛化
plot(x(1,1:9),x(2,1:9),'o',x(1,10:15),x(2,10:15),'*',X(1,:),X(2,:),'v')
grid on